package org.JQbitorrentClient.V2_3_8.docker;

import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;

import java.util.Arrays;

@Slf4j
public class QBittorrentDocker {
    static public GenericContainer genericContainer;
    static boolean isCreated = false;
    public static void start()
    {
        if(isCreated)
        {
            return;
        }

        genericContainer= new GenericContainer("nevinee/qbittorrent:4.6.4");
        genericContainer.withExposedPorts(8080)
                .withEnv("WEBUI_PORT", "8080")
                .withEnv("QB_USERNAME", "user")
                .withEnv("QB_PASSWORD", "useruser")
                .withEnv("BT_PORT", "34567")
                .withLogConsumer(new Slf4jLogConsumer(log))
                .waitingFor(Wait.forLogMessage(".*要控制 qBittorrent，请访问下列地址的.*", 1));
        genericContainer.setPortBindings(Arrays.asList("8080:8080"));
        genericContainer.start();
        isCreated = true;
    }
}
